/*package cn.wx.scholar.es.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.FuzzyQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csvreader.CsvReader;
import cn.wx.common.utils.UUIDGenerator;
import cn.wx.scholar.es.entity.EsField;
import cn.wx.scholar.es.repository.EsFieldRepository;

*//**
 * 全文检索
 * @author Administrator
 * http://www.cnblogs.com/double-yuan/p/9740494.html 多索引查询
 *//*
@Service
@Transactional
public class EsFieldService {
	
	protected final static float tieBreaker=0.6f;
	protected final static String type ="best_fields";
	protected final static String minimumShouldMatch="60%";
	protected final static String analyzer="ik_max_word";
	protected final static String queryGroupAll="query_group_all";
	protected final static String groupValue="groupValue";
	
	private final static String[] str = { "eName" };
	
	@Autowired
	private EsFieldRepository esFieldRepository;
	
	
	public List<EsField> queryFullText(String keyword) {
		
		if(StringUtils.isBlank(keyword)) {
			return null;
		}
		
		
		NativeSearchQueryBuilder searchQueryBuildera = new NativeSearchQueryBuilder();
		final String kw = keyword.trim();
		
		if(kw.indexOf(" ") == -1) {
			FuzzyQueryBuilder builder = QueryBuilders.fuzzyQuery("eName", keyword);
			searchQueryBuildera.withQuery(builder);
		}else{
			BoolQueryBuilder builder = QueryBuilders.boolQuery();
			MultiMatchQueryBuilder mb = QueryBuilders.multiMatchQuery(keyword, str);
			mb.minimumShouldMatch(minimumShouldMatch)
			.type(type)
			.tieBreaker(tieBreaker)
			.analyzer(analyzer)
			.fuzziness(Fuzziness.AUTO).prefixLength(keyword.length()-1);
			builder.must(mb);
			searchQueryBuildera.withQuery(builder);
		}

		*//**
		 * 创建查询builder
		 *//*
		searchQueryBuildera.withPageable(PageRequest.of(0, 10));
		searchQueryBuildera.withSearchType(SearchType.QUERY_THEN_FETCH);
		SearchQuery searchQuery = searchQueryBuildera.build();
		Page<EsField> page = esFieldRepository.search(searchQuery);
		return page.getContent();
	}
	
	
	public String create() {
		final String filePath = "E:\\my_read_csv\\allFosRelations.csv";
		try {
			
			CsvReader csvReader = new CsvReader(filePath);
			
			// 读表头
            csvReader.readHeaders();
            
            List<EsField> els = new ArrayList<>();
            EsField el = null;
            int i = 0;
            while (csvReader.readRecord()){
                // 读一整行
            	String line = csvReader.getRawRecord();
				if(StringUtils.isBlank(line)) {
					continue;
				}

				String fId = csvReader.get(0);
				String eName = csvReader.get(1);
				
				el = new EsField();
				el.setId(UUIDGenerator.getUUID());
				el.setfId(Long.parseLong(fId));
				el.seteName(eName);
				els.add(el);
				
				if(els.size() > 499) {
					i++;
					createBatch(els);
					els.clear();
					System.out.println("执行" + i +"次插入。");
				}
				
            }

            *//**
			 * 关闭读入流
			 *//*
			csvReader.close();
			csvReader = null;
            
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "succ";
	}
	
	*//**
	 * 批量插入
	 * @param efts
	 *//*
	public void createBatch(List<EsField> efts) {
		esFieldRepository.saveAll(efts);
	}
	
}
*/